import 'package:flutter/material.dart';
import 'home.dart';
import 'favorite.dart';
import 'package:flutter/cupertino.dart';
import 'component/drawer.dart';
import 'package:in_app_review/in_app_review.dart';
import 'diy/diy_me.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.initialIndex});
  // final String title;
  final int initialIndex;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final InAppReview inAppReview = InAppReview.instance;

  int thisIndex = 0;
  List menuOptions = [
    {'name': 'Inicio', 'index': 0, 'icon': const Icon(CupertinoIcons.home)},
    {'name': 'DIY', 'index': 1, 'icon': const Icon(CupertinoIcons.add_circled)},
    {'name': 'Favoritos', 'index': 2, 'icon': const Icon(CupertinoIcons.heart)},
    
    // {'name': 'Categorías', 'index': 2, 'icon': const Icon(CupertinoIcons.collections)},
    // {'name': 'Setting', 'index': 3, 'icon': const Icon(CupertinoIcons.settings)},
  ];
  List menuOptionsTitle = [
    {'name': 'Felicitaciones y Tarjetas', 'index': 0, 'icon': const Icon(CupertinoIcons.home)},
    {'name': 'DIY', 'index': 1, 'icon': const Icon(CupertinoIcons.add_circled)},
    {'name': 'Favoritos', 'index': 2, 'icon': const Icon(CupertinoIcons.heart)},
    
    // {'name': 'Categorías', 'index': 2, 'icon': const Icon(CupertinoIcons.collections)},
    // {'name': 'Setting', 'index': 3, 'icon': const Icon(CupertinoIcons.settings)},
  ];
  final controller = ScrollController();
  // static FirebaseAnalytics analytics = FirebaseAnalytics.instance;

  // Future<void> _logScreenView() async {
  //   await analytics.logScreenView(
  //     screenName: 'Home Page ES',
  //     screenClass: 'HomePage_ES',
  //   );
  // }

  @override
  void initState() {
    super.initState();
    thisIndex = widget.initialIndex;

   
  }


  @override
  void dispose() {
    super.dispose();
  }

  
  final List<Widget> _widgetOptions = <Widget>[
    const HomePage(),
    const DiyMePage(),
    const FavoritePage(),
  ];

  @override
  Widget build(BuildContext context) {
    var topHeight = MediaQuery.of(context).padding.top;

    return Stack(
      children: [
        Container(
          child: Scaffold(
            backgroundColor: Colors.white,
            appBar: PreferredSize(
              preferredSize: const Size.fromHeight(60),
              child: Container(
                decoration: BoxDecoration(
                  color: Colors.white,
                  boxShadow: [
                    BoxShadow(
                      color: Colors.black.withOpacity(0.1),
                      offset: const Offset(0, 2),
                      blurRadius: 6.0,
                    ),
                  ],
                ),
                child: AppBar(
                  backgroundColor: Colors.white,
                  title: Text(
                    menuOptionsTitle[thisIndex]['name'],
                    // 'Good Morning Wishes 2025',
                    style: const TextStyle(fontFamily: 'OpenSans', color: Colors.black, fontWeight: FontWeight.bold),
                  ),
                  actions: [
                    
                    IconButton(
                      icon: const Icon(CupertinoIcons.star),
                      onPressed: () => {inAppReview.openStoreListing(appStoreId: '6740426686')},
                      // child: const Icon(CupertinoIcons.star),
                    ),
                    // IconButton(
                    //   icon: const Icon(CupertinoIcons.star),
                    //   onPressed: () => {
                    //     Navigator.push(
                    //       context,
                    //       MaterialPageRoute(
                    //         builder: (context) => const InAppPurchasePage(
                              
                    //         ),
                    //       ),
                    //     )
                    //   },
                    //   // child: const Icon(CupertinoIcons.star),
                    // )
                  ],
                ),
              ),
              
            ),
            drawer: const CustomDrawer(),
            // body: SingleChildScrollView(
            //   controller: controller,
            //   child: _widgetOptions[thisIndex],
            // ),
            body: _widgetOptions[thisIndex],
            bottomNavigationBar: Container(
              child: CupertinoTabBar(
                // backgroundColor: const Color.fromARGB(255, 215, 31, 39),
                backgroundColor: Colors.white,
                height: 64,
                iconSize: 28,
                items: [
                  for (var menu in menuOptions)
                    BottomNavigationBarItem(icon: menu['icon'], label: menu['name'])
                ],
                currentIndex: thisIndex,
                // activeColor: Colors.black,
                activeColor: const Color.fromARGB(255, 215, 31, 39),
                inactiveColor: const Color.fromRGBO(0, 0, 0, .65),
                onTap: (value) {
                  setState(() {
                    thisIndex = value;
                  });
                },
              ),
            ) ,
          )
        ),
      ],
    ) ;

  }

}
